package com.hjsmallfly.syllabus.base

import android.os.Build
import android.os.Bundle
import android.support.v4.view.WindowCompat
import android.util.TypedValue
import android.view.WindowManager
import com.hjsmallfly.syllabus.App
import com.hjsmallfly.syllabus.R
import com.hjsmallfly.syllabus.util.ThemeUtil

abstract class BaseKtActivity : BaseActivity() {

    private val app: App
        get() = application as App

    public val appComponent by lazy { app.appComponent }

    override fun onCreate(savedInstanceState: Bundle?) {
        if (false) {
            super.onCreate(savedInstanceState)
        } else {
            superOnCreate(savedInstanceState)
        }
        initTheme()
        contentView = getContentView()
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
        }
        init(savedInstanceState)
    }

    override fun onDestroy() {
        uninit()
        super.onDestroy()
    }

    fun uninit() {}

    abstract fun init(savedInstanceState: Bundle?)

    private fun initTheme() {
        supportRequestWindowFeature(WindowCompat.FEATURE_ACTION_MODE_OVERLAY)
        setTheme(ThemeUtil.getInstance().style)

        val typedValue = TypedValue()
        theme.resolveAttribute(R.attr.colorPrimary, typedValue, true)
        ThemeUtil.getInstance().colorPrimary = typedValue.data

        theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true)
        ThemeUtil.getInstance().colorPrimaryDark = typedValue.data
    }


}